<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/3/2
  Time: 15:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<div class="row" style="padding:2px;margin-bottom: 5px ">
    <div class="col-sm-12 col-md-12 col-lg-12">
        <div >
            <shiro:hasAnyRoles name="wechat">
            <form id="searchForm" method="post" action="">
                <a id="ajax_proAttend_btn_add" class="btn btn-default " data-toggle="modal"><i class="fa fa-lg fa-plus"></i> 新建考勤设置</a>
                <input type="hidden" name="proInfoId" id="proInfoId" value="<s:property value="proInfoId" />"/>
            </form>
            </shiro:hasAnyRoles>
        </div>
    </div>
</div>

<section id="widget-grid" class="">
    <!-- row -->
    <div class="row">
        <!-- NEW WIDGET START -->
        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <!-- Widget ID (each widget will need unique ID)-->
            <div class="jarviswidget " id="wid-id-0" data-widget-editbutton="false"
                 data-widget-colorbutton="false"
                 data-widget-togglebutton="false"
                 data-widget-deletebutton="false"
                 data-widget-fullscreenbutton="true"
                 data-widget-custombutton="false"
                 data-widget-sortable="false">

                <!-- widget div-->
                <div>
                    <!-- widget edit box -->
                    <div class="jarviswidget-editbox">
                        <!-- This area used as dropdown edit box -->
                    </div>
                    <!-- end widget edit box -->
                    <!-- widget content -->
                    <div class="widget-body no-padding">
                        <div class="col-sm-12 col-md-12 col-lg-12">
                            <div class=" ">
                                <div class="row" id="ajax_proAttend_list_row">
                                    <table id="ajax_proAttend_table" class="table table-striped table-bordered table-hover">
                                    </table>
                                    <div id="ajax_proAttend_list_page">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- end widget content -->

                </div>
                <!-- end widget div -->
            </div>
            <!-- end widget -->
        </article>
        <!-- WIDGET END -->
    </div>
    <!-- end row -->
</section>

<script type="text/javascript">
    // DO NOT REMOVE : GLOBAL FUNCTIONS!
    pageSetUp();

    $("#ajax_proAttend_btn_add").click(function(){
        loadURL("ajax-pro-attend!input.action?proInfoId="+$("#proInfoId").val(),$('div#s2'));
    });

</script>
<script type="text/javascript">
    $(function(){
        load_proAttend_jqGrid();
    });

    function load_proAttend_jqGrid(){
        jQuery("#ajax_proAttend_table").jqGrid({
            url:'ajax-pro-attend!list.action?proInfoId='+$("#proInfoId").val(),
            datatype: "json",
            colNames:['正常考勤时间区间',"迟到考勤时间区间","备注","操作","id"],
            colModel:[
                {name:'regularPeriod',index:'regularPeriod', width:200},
                {name:'unRegularPeriod',index:'unRegularPeriod', width:200},
                {name:'mark',index:'mark', width:300},
                {name:'act',index:'act', width:150,sortable:false,fixed:true},
                {name:'id',index:'id',hidden:true}
            ],
            rowNum : 10,
            rowList:[10,20,30],
            pager : '#ajax_proAttend_list_page',
            //sortname : 'id',
            //sortorder : "asc",
            gridComplete:function(){
                var ids=$("#ajax_proAttend_table").jqGrid('getDataIDs');
                for(var i=0;i<ids.length;i++){
                    var cl=ids[i];
                    //var rowData = $("#ajax_proAttend_table").jqGrid("getRowData",cl);
                    var de="<button class='btn btn-default' data-original-title='编辑' onclick=\"fn_proAttend_edit('"+cl+"');\"><i class='fa fa-pencil'></i>编辑</button>"+" ";
                    var dt="<button class='btn btn-default' data-original-title='删除' onclick=\"fn_proAttend_destroy('"+cl+"');\"><i class='fa fa-ban'></i>删除</button>"+" ";
                    if($("#ajax_proAttend_btn_add").length==0){
                        de="";
                        dt="";
                    }
                    jQuery("#ajax_proAttend_table").jqGrid('setRowData',ids[i],{act:de+dt});
                }
                $(".ui-jqgrid-bdiv").css("overflow-x","hidden");
                jqGridStyle();
            },
            jsonReader: {
                root: "dataRows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems : false
            },
            multiselect : false,
            rownumbers:true,
            gridview:true,
            shrinkToFit:true,
            viewrecords: true,
            autowidth: true,
            height:'auto',
            forceFit:true,
            loadComplete: function() {
            }
        });
        $(window).on('resize.jqGrid', function() {
            jQuery("#ajax_proAttend_table").jqGrid('setGridWidth', $("#ajax_proAttend_list_row").width());
        });

        jQuery("#ajax_proAttend_table").jqGrid('navGrid', "#ajax_proAttend_list_page", {
            edit : false,
            add : false,
            del : false,
            search:false
        });
    }

    function fn_proAttend_edit(id){
        loadURL("ajax-pro-attend!input.action?keyId="+ id +"&proInfoId=" + $("#proInfoId").val(),$('div#s2'));
    }

    function fn_proAttend_destroy(id){
        var vActionUrl = "<%=path%>/com/ajax-pro-attend!delete.action";
        data={keyId:id};
        ajax_action(vActionUrl,data,{},function(pdata){
            _show(pdata);
        });
        jQuery("#ajax_proAttend_table").trigger("reloadGrid");
    }
</script>